import {routerRedux} from 'dva/router';
import {message} from 'antd';
import { userGeneral, userProvince, userSex} from '../services/api';

export default {
  namespace: 'userAnalysis',
  state: {
    data: {},
    sex : [],
    province : [],
  },

  effects: {
    *fetch({payload}, {call, put}){
      const res = yield call(userGeneral, payload);
      if (res) {
        yield put({
          type: 'save',
          payload: {data: res}
        });
      }
    },
    *fetchProvince({payload}, {call, put}){
      const res = yield call(userProvince, payload);
      if (res) {
        yield put({
          type: 'save',
          payload: {province: res}
        });
      }
    },
    *fetchSex({payload}, {call, put}){
      const res = yield call(userSex, payload);
      if (res) {
        yield put({
          type: 'save',
          payload: {sex: res}
        });
      }
    },
  },

  reducers: {
    save(state, {payload}){
      return {
        ...state,
        ...payload
      }
    },
    clear() {
      return {
        data: {},
        sex : [],
        province : [],
      };
    },
  },
};
